package com.wu.apiorder.controller;

import com.wu.apiorder.mapper.OrderMapper;
import com.wu.common.entity.Order;
import com.wu.common.entity.ResultData;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author whx
 * @date 2021/7/9
 */
@RestController
@RequestMapping("/order")
public class OrderController {

    @Value("${server.port}")
    String port;

    @Autowired
    OrderMapper orderMapper;

    @GetMapping("/list")
    public ResultData list(){
        List<Order> list = new ArrayList<>();
        list.add(new Order(1,"1111_"+port,new Date()));
        list.add(new Order(2,"2222_"+port,new Date()));
        list.add(new Order(3,"3333_"+port,new Date()));
        return new ResultData().SUCCESS(list);
    }

    @PostMapping("/getById")
    public ResultData getById(Integer id){
        return new ResultData().SUCCESS(new Order(id,id+"_"+port,new Date()));
    }

    @GetMapping("/findAll")
    public ResultData findAll(){
        List<Order> list = orderMapper.findAll();
        return new ResultData().SUCCESS(list);
    }

    @PostMapping("/update")
    public ResultData update(int id){
        orderMapper.update(id);
        int i = 1/0;
        return new ResultData().SUCCESS("success");
    }


}
